//  HomeController.swift
//  iostest
//
//  Created by jin on 2024/8/5.
//

import UIKit

class HomeController: UIViewController {
    
    ///列表数据
    var dataArrays:[String] = []

    @IBOutlet weak var imgTableView: UITableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        ///添加假数据
        for index in 1...8{
            dataArrays.append("\(index)")
        }
        
        imgTableView.dataSource = self
        
        imgTableView.delegate = self
        
        ///重新渲染到列表
        imgTableView.reloadData()
    }
    

    @IBAction func logoutClick(_ sender: Any) {
        ///退出登录
        PreferenceUtil.setLogin(false)
        SceneDelegate.shared.toLogin()
    }

}

extension HomeController :UITableViewDataSource,UITableViewDelegate{
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataArrays.count;
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "ImgCell", for: indexPath) as! ImgViewCell
        
        cell.bind(dataArrays[indexPath.row])
        
        return cell
    }
    
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let data = dataArrays[indexPath.row]
        let controller = storyboard?.instantiateViewController(withIdentifier: "ImgDetail") as! ImgDetailController
        controller.id = data
        navigationController?.pushViewController(controller, animated: true)
    }
    
}
